package com.opgea.token.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.opgea.token.dao.AbstractDAO;
import com.opgea.token.dao.EmployeeDocumentDAO;
import com.opgea.token.domain.entities.EmployeeDocument;
@Repository
public class EmployeeDocumentDAOImpl extends AbstractDAO<EmployeeDocument>
	implements EmployeeDocumentDAO {

    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public EmployeeDocument find(Long documentId) {
	@SuppressWarnings("unchecked")
	List<EmployeeDocument> objects = sessionFactory.getCurrentSession()
		.createCriteria(EmployeeDocument.class)
		.add(Restrictions.eq("id", documentId)).list();
	System.out.println(objects.get(0));
	return objects.get(0);
    }

    @Override
    public EmployeeDocument findDocumentByType(Long tutorId, String documentType) {
	String queryString = "from TutorDocument d";
	Query query = sessionFactory.getCurrentSession().createQuery(
		queryString);
	System.out.println("QueryString: " + query.getQueryString());
	EmployeeDocument document = (EmployeeDocument) query.list().get(0);
	return document;
    }

}
